package cn.stu.cms.controller;

import cn.stu.cms.dto.PageDto;
import cn.stu.cms.pojo.Teams;
import cn.stu.cms.service.TeamsService;
import cn.stu.cms.util.R;
import cn.stu.cms.vo.TeamsVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * (Teams)表控制层
 *
 * @author gh
 * @since 2023-07-21 17:11:32
 */
@RestController
@RequestMapping("/teams")
@AllArgsConstructor
public class TeamsController {

    private final TeamsService teamsService;

    /**
     * 查询全部对象
     *
     * @param pageDto 页数到页
     * @param teams   团队
     * @return 全部数据
     */
    @GetMapping("/page")
    public R<Page<Teams>> queryList(PageDto<Teams> pageDto, Teams teams) {
        return teamsService.getList(pageDto, teams);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R<TeamsVo> queryById(@PathVariable Long id) {
        return teamsService.getTeamById(id);
    }

    /**
     * 新增数据
     *
     * @param teams 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public R<Boolean> save(@RequestBody @Valid Teams teams) {
        return teamsService.add(teams);
    }

    /**
     * 编辑数据
     *
     * @param teams 实体
     * @return 编辑结果
     */
    @PutMapping("/edit")
    public R<Boolean> edit(@RequestBody @Valid Teams teams) {
        return teamsService.edit(teams);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public R<Boolean> deleteById(@PathVariable Long id) {
        return teamsService.deleteById(id);
    }




}

